package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.FormControl;
import com.amsp.oa.oademo.service.FormControlService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "表单管制管理")
@RestController
@RequestMapping("/api/form-control")
public class FormControlController {

    @Resource
    private FormControlService formControlService;

    @ApiOperation("批量保存表单")
    @PostMapping("/batch-save")
    public void batchSave(@RequestBody List<FormControl> formControls) {
        formControlService.saveBatch(formControls);
    }

    @ApiOperation("获取表单详情")
    @GetMapping("/{id}")
    public FormControl getById(@PathVariable Long id) {
        return formControlService.getById(id);
    }

    @ApiOperation("获取表单列表")
    @GetMapping("/list")
    public IPage<FormControl> list(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String keyword) {
        return formControlService.getList(new Page<>(current, size), keyword);
    }

    @ApiOperation("删除表单")
    @DeleteMapping("/{id}")
    public void delete(@PathVariable Long id) {
        formControlService.deleteById(id);
    }
}